package com.szgr.baoyin.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.szgr.baoyin.MainActivity;
import com.szgr.baoyin.MyApplication;
import com.szgr.baoyin.R;
import com.szgr.baoyin.utils.Constant;

public class ProtectRuleActivity extends BaseActivity {

    private View btn_now;
    private View btn_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_protect_rule);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initActionBar() {
        actionBarTitle.setText("维保条款");
    }

    @Override
    public void initView() {

        btn_now = findViewById(R.id.protect_rule_buy);
        btn_now.setOnClickListener(this);
        btn_back = findViewById(R.id.protect_rule_back);
        btn_back.setOnClickListener(this);

        WebView webView = (WebView) findViewById(R.id.protect_rule_web_view);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        webView.loadUrl(Constant.URL_PROTECT_RULE);

        Intent intent = getIntent();
        if(intent.hasExtra("fromBuy")){
            btn_now.setVisibility(View.GONE);
            btn_back.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.action_bar_left:
                finish();
                break;
            case R.id.protect_rule_buy:
                if(MyApplication.getmInstance().isLogin()) {
                    startActivity(new Intent(this, BuyProtectActivity.class));
                }else{
                    startActivity(new Intent(this,LoginActivity.class));
                }
                break;
            case R.id.protect_rule_back:
                Intent backIntent = new Intent(this, MainActivity.class);
                backIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(backIntent);
                break;
        }
    }
}
